package com.example.Lezedata.ui.dataPage.subVc;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

import androidx.annotation.NonNull;

import com.example.Lezedata.R;
import com.example.Lezedata.dataManager.GBUserManager;
import com.example.Lezedata.net.GBError;
import com.example.Lezedata.net.GBNetRequest;
import com.example.Lezedata.net.ServerResponseObserver;
import com.example.Lezedata.ui.activity.baseClass.GBBaseVc;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

import bid.Bid;
import common.Common;

public class ChequeDetailList extends GBBaseVc {
    @Override
    protected int getLayoutId() {
        return R.layout.cheque_detail_list;
    }

    @Override
    public CharSequence title() {
        return "支票列表";
    }
    private ListView listView;

    ArrayList<Bid.ChequesRecord> pools = new ArrayList<>();
    @Override
    protected void viewDidLoad() {
        super.viewDidLoad();
        listView = findViewById(R.id.listView);
        listView.setAdapter(adapter);
        hudShow();
        loadData();
    }

    void loadData(){
        String ip = getIntent().getStringExtra("ip");
        String id = getIntent().getStringExtra("id");
        Bid.GetNodeChequeJournalRequest request = Bid.GetNodeChequeJournalRequest.newBuilder().setBeeVersion(Bid.BeeVersion.BV_062).setEc2Id(id).setIpInner(ip).build();
        GBNetRequest.stubUser().getNodeChequeJournal(request, ServerResponseObserver.observer(new ServerResponseObserver.requestListener<Bid.GetNodeChequeJournalResponse>() {
            @Override
            public void complete(Bid.GetNodeChequeJournalResponse value, GBError error) {
                hudDismiss();
                if (error == null){
                    pools.addAll(value.getChequesList());
                    adapter.notifyDataSetChanged();
                }
            }
        }));
    }

    BaseAdapter adapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return pools.size();
        }

        @Override
        public Bid.ChequesRecord getItem(int position) {
            return pools.get(position);
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null){
                convertView = ChequeDetailListCell.newInstance(mContext,listView);
            }
            ChequeDetailListCell cell = (ChequeDetailListCell)convertView;
            cell.setPool(getItem(position));
            return convertView;
        }
    };

}